#include <windows.h>
#include <stdio.h>

int main()
{
    while (1)
	{
        // 检测WASD键状态
        short state = GetAsyncKeyState('W');
        if (state & 0x8000)
		{
            printf("W键被按下\n");
        }
        state = GetAsyncKeyState('A');
        if (state & 0x8000)
		{
            printf("A键被按下\n");
        }
		state = GetAsyncKeyState('S');
        if (state & 0x8000)
		{
            printf("S键被按下\n");
        }
		state = GetAsyncKeyState('D');
        if (state & 0x8000)
		{
            printf("D键被按下\n");
        }
        // 检测F1键状态
        state = GetAsyncKeyState(VK_F1);
        if (state & 0x8000)
		{
            break;
        }
        Sleep(100); // 暂停100毫秒
    }
    printf("程序结束\n");
    return 0;
}
